package com.itheima.controller;

import com.itheima.goods.pojo.Brand;
import com.itheima.goods.pojo.Category;
import com.itheima.service.CategoryService;
import entity.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/category")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    //分页查询
    @RequestMapping("/search/{page}/{size}")
    public Result<Object> findPage(@PathVariable("page") Integer page,@PathVariable("size") Integer size){
        return categoryService.findPage(page,size);
    }

    //修改前数据回显
    @RequestMapping(value = "{id}",method = RequestMethod.GET)
    public Result<Object> findById(@PathVariable("id") Integer id){
        return categoryService.findById(id);
    }

    //修改
    @RequestMapping(value = "{id}",method = RequestMethod.PUT)
    public Result<Object> updateCategoryById(@RequestBody Category category){
        return categoryService.updateCategoryById(category);
    }

    //删除
    @RequestMapping(value = "{id}",method = RequestMethod.DELETE)
    public Result<Object> deleteCategoryById(@PathVariable("id") Integer id){
        return categoryService.deleteCategoryById(id);
    }

    //添加
    @RequestMapping(method = RequestMethod.POST)
    public Result<Object> addCategory(@RequestBody Category category){
        return categoryService.addCategory(category);
    }

}
